/**
 * Copyright &copy; com.nmf
 */
package com.nmf.site.biz.paygoods.gen.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.nmf.site.common.config.Global;
import com.nmf.site.common.persistence.Page;
import com.nmf.site.common.web.BaseController;
import com.nmf.site.common.utils.StringUtils;
import com.nmf.site.biz.paygoods.gen.entity.BizPayOrder;
import com.nmf.site.biz.paygoods.gen.service.BizPayOrderService;

/**
 * 支付商品Controller
 * @author 北冥
 * @version 2018-04-14
 */
@Controller
@RequestMapping(value = "${adminPath}/gen/bizPayOrder")
public class BizPayOrderController extends BaseController {

	@Autowired
	private BizPayOrderService bizPayOrderService;
	
	@ModelAttribute
	public BizPayOrder get(@RequestParam(required=false) String id) {
		BizPayOrder entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bizPayOrderService.get(id);
		}
		if (entity == null){
			entity = new BizPayOrder();
		}
		return entity;
	}
	
	@RequiresPermissions("gen:bizPayOrder:view")
	@RequestMapping(value = {"list", ""})
	public String list(BizPayOrder bizPayOrder, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BizPayOrder> page = bizPayOrderService.findPage(new Page<BizPayOrder>(request, response), bizPayOrder); 
		model.addAttribute("page", page);
		return "paygoods/gen/bizPayOrderList";
	}

	@RequiresPermissions("gen:bizPayOrder:view")
	@RequestMapping(value = "form")
	public String form(BizPayOrder bizPayOrder, Model model) {
		model.addAttribute("bizPayOrder", bizPayOrder);
		return "paygoods/gen/bizPayOrderForm";
	}

	@RequiresPermissions("gen:bizPayOrder:edit")
	@RequestMapping(value = "save")
	public String save(BizPayOrder bizPayOrder, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bizPayOrder)){
			return form(bizPayOrder, model);
		}
		bizPayOrderService.save(bizPayOrder);
		addMessage(redirectAttributes, "保存支付商品成功");
		return "redirect:"+Global.getAdminPath()+"/gen/bizPayOrder/?repage";
	}
	
	@RequiresPermissions("gen:bizPayOrder:edit")
	@RequestMapping(value = "delete")
	public String delete(BizPayOrder bizPayOrder, RedirectAttributes redirectAttributes) {
		bizPayOrderService.delete(bizPayOrder);
		addMessage(redirectAttributes, "删除支付商品成功");
		return "redirect:"+Global.getAdminPath()+"/gen/bizPayOrder/?repage";
	}

}